import { db } from "@/db";
import { tasks } from "@/db/schema";
import { baseProcedure, createTRPCRouter, protectedProcedure } from "@/trpc/init"
import { eq } from "drizzle-orm";
import { z } from "zod";
// tasks 路由

const queryShema = z.object({
  id: z.number(),
})


export const tasksRouter = createTRPCRouter({
  getMany: baseProcedure.query(async ({ctx}) => {
    // console.log(ctx.user.id,"这里数据333")
    // if (!ctx.user?.id) {
    //   throw new Error('用户未认证');
    // }
    const data = await db.select().from(tasks).where(eq(tasks.userId,  ctx.user?.id ?? '', ))
    console.log(data,"这里数据44444")
    return data
  }),
  getOne: baseProcedure.input(queryShema).query(async (opts) => {
    const { input } = opts
    const data = await db.select().from(tasks).where(eq(tasks.id, Number(input.id))).limit(1)
    return data[0]
  })
})
